package com.sebiotec.manager.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.manager.R;
import com.sebiotec.manager.R2;
import com.sebiotec.manager.ui.view.LangDialogFragment;


import butterknife.BindView;
import butterknife.OnClick;

public class LanguageActivity extends BaseActivity implements LangDialogFragment.ConfirmListener {


    @BindView(R2.id.qk_back)
    ImageView qkBack;
    @BindView(R2.id.iv_zh)
    ImageView ivZh;
    @BindView(R2.id.cl1)
    ConstraintLayout cl1;
    @BindView(R2.id.iv_en)
    ImageView ivEn;
    @BindView(R2.id.cl2)
    ConstraintLayout cl2;
    private boolean isSeleced=true; //true 選中en  false zh

    @Override
    protected int setLayoutId() {
        return R.layout.man_activity_language;
    }

    @Override
    protected void initUI() {
        int smjSetLanguageLocales = LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity());
        if (smjSetLanguageLocales==1){
            ivEn.setVisibility(View.GONE);
            ivZh.setVisibility(View.VISIBLE);
            isSeleced=false;
        }else{
            ivEn.setVisibility(View.VISIBLE);
            ivZh.setVisibility(View.GONE);
            isSeleced=true;
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {

    }


    @OnClick({R2.id.cl1, R2.id.cl2,R2.id.qk_back})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.cl1) {
            if (isSeleced){
                LangDialogFragment.newInstance("zh").show(getSupportFragmentManager(),"");
            }


        } else if (id == R.id.cl2) {
            if (!isSeleced){
                LangDialogFragment.newInstance("en").show(getSupportFragmentManager(),"");
            }


        }else if (id==R.id.qk_back){
            ActivityTool.getInstance().popOneActivity(this);
        }
    }


    @Override
    public void onClickComplete(String tittle) {
        if ("zh".equals(tittle)){
            //切換方法
            LocalManageUtil.saveSelectLanguage(LanguageActivity.this, 2);
            isSeleced=false;
            ivEn.setVisibility(View.GONE);
            ivZh.setVisibility(View.VISIBLE);
            Bundle bundle = new Bundle();        //得到bundle对象
            bundle.putString("language", "11");
            ActivityTool.getInstance().finishAllActivities();
            ARouter.getInstance().build("/App/ManagerMainActivity").withBundle("language", bundle).navigation();


        }else{
            LocalManageUtil.saveSelectLanguage(LanguageActivity.this, 3);
            isSeleced=true;
            ivEn.setVisibility(View.VISIBLE);
            ivZh.setVisibility(View.GONE);
            Bundle bundle = new Bundle();        //得到bundle对象
            bundle.putString("language", "11");
            ActivityTool.getInstance().finishAllActivities();
            ARouter.getInstance().build("/App/ManagerMainActivity").withBundle("language", bundle).navigation();

        }
    }
}
